SHELL=		/bin/bash

NAME=		fastdfs
VERSION=	6.08
URL=		https://codeload.github.com/happyfish100/$(NAME)/tar.gz/refs/tags/V$(VERSION)

CONTRIB?=	./
CONTRIB:=	$(abspath $(CONTRIB))

BASE_RELEASE=	1
SRCPATH?=	./SOURCES
BUILD_ENV_PATH=	${HOME}/rpmbuild
MODSRC_PREFIX=
BUILD_DIR=	%{bdir}

export CR=\\n

all:	prep download build

prep:
	@yum install -y rpm-build libcurl-devel ; \
	mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

download:
	@echo "===> Download the source package for ${NAME}-${VERSION}.tar.gz" ; \
	$(SHELL) -c "cd ${SRCPATH} && curl -ko ${NAME}-${VERSION}.tar.gz ${URL} --progress" ; \
	tar xf ${SRCPATH}/${NAME}-${VERSION}.tar.gz --strip-components=1 -C ${BUILD_ENV_PATH}/SPECS ${NAME}-${VERSION}/${NAME}.spec

build:
	@echo "===> Building package" ; \
	sed -i "s#%define FDFSVersion .*#%define FDFSVersion ${VERSION}#" ${BUILD_ENV_PATH}/SPECS/${NAME}.spec
	sed -i '78a install -m 0644 conf/http.conf %{buildroot}%{_sysconfdir}/fdfs/http.conf' ${BUILD_ENV_PATH}/SPECS/${NAME}.spec
	sed -i '79a install -m 0644 conf/mime.types %{buildroot}%{_sysconfdir}/fdfs/mime.types' ${BUILD_ENV_PATH}/SPECS/${NAME}.spec
	sed -i '125a /etc/fdfs/http.conf' ${BUILD_ENV_PATH}/SPECS/${NAME}.spec
	sed -i '126a /etc/fdfs/mime.types' ${BUILD_ENV_PATH}/SPECS/${NAME}.spec
	$(SHELL) -c "time -p rpmbuild -ba ${BUILD_ENV_PATH}/SPECS/${NAME}.spec"

clean:
	@rm -rf ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS,BUILDROOT}
